import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
import { WithStyles } from "@material-ui/core/styles/withStyles";
import * as React from "react";
import { useEffect, useState } from "react";
import SearchAndFilter from "../../component/SearchAndFilter";
import { doctorDept, doctorPosition } from "./ParamConfig";
import { Card, List } from "antd";
import { IfilterParam } from "../../type/CommonData";
import service from "../../axios/Service";
import { Link } from "react-router-dom";

const styles = (theme: Theme) =>
  createStyles<"root">({
    root: {}
  });

interface Iprops extends WithStyles<typeof styles> {}

/**
 * 描述：
 *  从医生查找
 * @author sunshixiong
 * @date 2019/3/27-17:12
 */
const DoctorCheck = (props: Iprops) => {
  const [data, setData] = useState([]);
  useEffect(() => {
    getData();
  }, []);
  const getData = (params?: IfilterParam) => {
    service
      .get("/portalDoctors/query", {
        params
      })
      .then(value => {
        if (value.data._embedded && value.data._embedded.portalDoctors) {
          setData(value.data._embedded.portalDoctors);
        }
      });
  };
  return (
    <div>
      <SearchAndFilter
        arrayOne={doctorPosition}
        arrayTwo={doctorDept}
        filterCallback={getData}
        filterOne={"医生职称"}
        filterTwo={"所属科室"}
        Placeholder={"请输入医生名字"}
      />

      <Card style={{ marginTop: 20 }}>
        <List
          dataSource={data}
          split={false}
          grid={{ column: 4, gutter: 10 }}
          renderItem={(item: any) => (
            <List.Item>
              <Link to={{ pathname: "/detail-doctor", state:  item  }}>
                <span>
                  {item.name}
                  <span style={{ color: "rgb(255,195,87)", marginLeft: 10 }}>
                    {item.hospital}
                  </span>
                </span>
              </Link>
            </List.Item>
          )}
          pagination={{}}
        />
      </Card>
    </div>
  );
};

export default withStyles(styles)(DoctorCheck);
